/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Facades;

import Entities.Employee;
import Entities.Employee;
import Entities.User;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author roycalderon
 */
@Stateless
public class EmployeeFacade extends AbstractFacade<Employee> {

    @PersistenceContext(unitName = "MaRoY-LibraryPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public EmployeeFacade() {
        super(Employee.class);
    }

    //Roy: user4Login
    public Employee FindbyUser(User entidadUsuario) {
        Query query = em.createNamedQuery("Employee.findByUser_id");
        query.setParameter("userid", entidadUsuario);
        Employee aux;
        try {
            aux = (Employee) query.getSingleResult();
            if (aux != null) {
                return aux;
            } else {
                return null;
            }
        } catch (Exception e) {
            return null;
        }
    }
}
